package com.tpo.jnotes.client.layer.model.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Table;

import com.tpo.jnotes.client.lib.interfaces.IModelEntity;
import com.tpo.jnotes.client.lib.language.Bundle;
import com.tpo.jnotes.client.lib.util.BeansUtils;
import com.tpo.jnotes.client.lib.util.StringsUtils;
import com.tpo.jnotes.client.main.Logging;

@Entity
@Table( name = "NOTES" )
public class ENote implements IModelEntity
{
    private String text;
    private String title;
    private int id;

    public ENote()
    {
        text = Bundle.getString( "model.note.text" );
        title = Bundle.getString( "model.note.title" );
    }

    public String getText()
    {
        return text;
    }

    public void setText( String text )
    {
        if( !StringsUtils.equals( text, this.text ) )
        {
            Logging.trace( "ENote > setting text(id = " + id + "). TEXT = " + text );
            this.text = text;
        }
    }

    public String getTitle()
    {
        return title;
    }

    public void setTitle( String title )
    {
        if( !StringsUtils.equals( title, this.title ) )
        {
            Logging.trace( "ENote > setting title(id = " + id + "). TITLE = " + title );
            this.title = title;
        }

    }

    @Override
    @javax.persistence.Id
    @GeneratedValue( strategy = GenerationType.SEQUENCE )
    public int getId()
    {
        return id;
    }

    public void setId( int id )
    {
        this.id = id;
    }

    @Override
    public Object getProperty( String propertyName )
    {
        return BeansUtils.getBeanProperty( this, propertyName );
    }

    @Override
    public void setProperty( String propertyName, Object propertyValue )
    {
        Logging.trace( "ENote > (ID = " + id + "). setting " + propertyName + " = " + propertyValue );
        BeansUtils.setProperty( this, propertyName, propertyValue );
    }
}
